package com.mars.foodserver.controller.admin;

import com.mars.foodserver.request.SysUserRequest;
import com.mars.foodserver.request.UserRequest;
import com.mars.foodserver.response.UserResponse;
import com.mars.foodserver.response.result.R;
import com.mars.foodserver.service.ISysUserService;
import org.springframework.web.bind.annotation.*;
import lombok.AllArgsConstructor;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 运营后台用户表 前端控制器
 * </p>
 *
 * @author wq
 * @since 2021-07-19
 */
@RestController
@RequestMapping("admin/sysUser")
@AllArgsConstructor
public class SysUserController {

    final ISysUserService sysUserService;

    /**
     * 登录
     *
     * @param request 请求参数
     * @return R
     */
    @PostMapping("/login")
    public R<UserResponse> login(@RequestBody SysUserRequest request) {
        return R.success(sysUserService.login(request));
    }


    /**
     * 注册
     *
     * @param request 请求参数
     */
    @PostMapping("/register")
    public R register(@RequestBody SysUserRequest request) {
        sysUserService.register(request);
        return R.success();
    }

    /**
     * 分页
     *
     * @param request 请求参数
     * @return R
     */
    @PostMapping("/page")
    private R page(@RequestBody SysUserRequest request) {
        return R.success(sysUserService.page(request));
    }

    /**
     * 退出登录
     *
     * @param request 请求参数
     * @return R
     */
    @GetMapping("/logout")
    public R logout(HttpServletRequest request) {
        sysUserService.logout(request);
        return R.success();
    }
}
